package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;
import androidx.viewpager.widget.ViewPager;

import android.os.Bundle;
import android.widget.RadioButton;
import android.widget.RadioGroup;

public class BannerActivity extends AppCompatActivity {

    int[] images = new int[]{
            R.drawable.banner1,
            R.drawable.banner2,
            R.drawable.banner3,
            R.drawable.banner4,
            R.drawable.banner5
    };
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_banner);

        // 通过id获取viewpager组件
        ViewPager viewPager = findViewById(R.id.viewpager);
        BannerViewPagerAdapter viewPagerAdapter =
                new BannerViewPagerAdapter(this, images);
        viewPager.setAdapter(viewPagerAdapter);

        RadioGroup radioGroup = findViewById(R.id.radio_group);
        // 怎么动态生成组件？
        for(int i=0; i<images.length; i++) {
            RadioButton radioButton = new RadioButton(this);  // 生成一个RadioButton对象，也叫动态生成组件
            radioGroup.addView(radioButton); // 将生成的RadioButton放入到RadioGroup中
        }
    }
}